package com.ljx.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljx.api.entity.Role;
import com.ljx.api.mapper.RoleMapper;
import com.ljx.api.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @类名: RoleServiceImpl
 * @描述:
 * @日期: 2020-09-08 14:29
 * @作者: 刘纪譞
 * @版本: 1.0.0
 * <p>
 * since JDK 1.8
 **/

    @Service
    @Slf4j
    public class RoleServiceImpl implements RoleService {
        @Autowired
        private RoleMapper roleMapper;

        @Override
        public boolean insert(Role role) {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("role_name", role.getRoleName());
            List<Role> roles = roleMapper.selectList(queryWrapper);
            System.out.println(roles.size());
            if (roles.size() <= 0) {
                log.info("aa");
                roleMapper.insert(role);
                return true;
            }
            return false;
        }

        @Override
        public boolean delete(Long id) {
            if(roleMapper.deleteById(id)>0){
                return true;
            }
            return false;
        }

        @Override
        public boolean update(Role role) {
            if(roleMapper.updateById(role)>0){
                return true;
            }
            return false;
        }
    }
